<div class="fieldset">
    <div class="form-section required">
        <div class="form_item_block">
            <%= required_label(scope[:form], :name, 'Job Name') %>

                <%= scope[:form].text_field :name %>
                <%= error_message_on(scope[:job], com.thoughtworks.go.config.JobConfig::NAME, :css_class => "form_error") %>

        </div>
        <div class="form_item_block">
            <%= scope[:form].label com.thoughtworks.go.config.JobConfig::RESOURCES, 'Resources' %>

                <%= scope[:form].text_field com.thoughtworks.go.config.JobConfig::RESOURCES, :class => "resources_auto_complete", :value => scope[:job].resourceConfigs().exportToCsv() %>
                <div class="contextual_help has_go_tip_right" title="Agent resources that this job requires to run"></div>
                <%- scope[:job].resourceConfigs().each do |resource| -%>
                    <%= error_message_on(resource, com.thoughtworks.go.config.JobConfig::RESOURCES, :css_class => "form_error") -%>
                <%- end -%>

            <div class="inline_instruction">
                Comma separated list
            </div>
        </div>
        <div class="form_item_block">
            <%= scope[:form].label "elasticProfileId", "Elastic Profile Id" %>

                <%= scope[:form].text_field "elasticProfileId", :class => 'elastic_profile_id', :value => scope[:job].getElasticProfileId() %>
                <div class="contextual_help has_go_tip_right" title="Elastic Profile that this job requires to run.<br/><a href='<%= '/go/admin/elastic_agent_configurations' %>' target='_blank'>Click here</a> to see and manage all elastic profiles."></div>
                <%= error_message_on(scope[:job], "elasticProfileId", :css_class => "form_error") %>

         </div>
         </div>
  <div class="form-section">
        <div class="form_item_block">
          <div class="help-wrapper">
            <%= scope[:form].label com.thoughtworks.go.config.JobConfig::TIMEOUT, 'Job Timeout', :class => "before_tip" %>
            <div class="contextual_help has_go_tip_right" title="If this job is inactive for more than the specified period (in minutes), Go will cancel it."></div>
          </div>


            <div class="checkbox_row">
                <%= scope[:form].radio_button 'timeoutType', com.thoughtworks.go.config.JobConfig::NEVER_TIMEOUT, :id => "jobTimeout_never" -%>
                <%= label_tag "jobTimeout_never", 'Never' -%>
            </div>

            <div class="checkbox_row">
                <%= scope[:form].radio_button 'timeoutType', com.thoughtworks.go.config.JobConfig::DEFAULT_TIMEOUT, :id => "jobTimeout_default" -%>
                <%= label_tag "jobTimeout_default", "#{'Use default'} (#{default_job_timeout_for_display(scope[:cruise_config])})"-%>
            </div>

            <div class="override_timeout checkbox_row">
                <%= scope[:form].radio_button 'timeoutType', com.thoughtworks.go.config.JobConfig::OVERRIDE_TIMEOUT, :id => "jobTimeout_override" -%>
                <%= label_tag "jobTimeout_override", 'Cancel after'  -%>
                <%= scope[:form].text_field com.thoughtworks.go.config.JobConfig::TIMEOUT, :class => "inline small_text_field" %>
                <%= label_tag "jobTimeout_override", 'minute(s) of inactivity' -%>
            </div>
        </div>
        </div>

        <div class="form-section">
            <%= scope[:form].label com.thoughtworks.go.config.JobConfig::RUN_TYPE, 'Run Type', :class => "before_tip" %>

            <div class="clear"></div>
            <%= error_message_on(scope[:job], com.thoughtworks.go.config.JobConfig::RUN_TYPE, :css_class => "form_error") %>
            <div class="clear"></div>

            <div class="checkbox_row">
                <%= scope[:form].radio_button 'runType', com.thoughtworks.go.config.JobConfig::RUN_SINGLE_INSTANCE, :id => "jobRunType_runSingleInstance" -%>
                <%= label_tag "jobRunType_runSingleInstance", 'Run one instance' -%>
            </div>

            <div class="checkbox_row">
               <div class="help-wrapper">
                 <%= scope[:form].radio_button 'runType', com.thoughtworks.go.config.JobConfig::RUN_ON_ALL_AGENTS, :id => "jobRunType_runOnAllAgents" -%>
                <%= label_tag "jobRunType_runOnAllAgents", 'Run on all agents' -%>
                <span class="contextual_help has_go_tip_right" title=" Job will run on all agents that match its resources (if any) and are in the same environment as this job’s pipeline. This option is particularly useful when deploying to multiple servers."></span>
               </div>
            </div>

            <div class="override_timeout checkbox_row">
              <div class="help-wrapper">
                <%= scope[:form].radio_button 'runType', com.thoughtworks.go.config.JobConfig::RUN_MULTIPLE_INSTANCE, :id => "jobRunType_runMultipleInstances" -%>
                <%= label_tag "jobRunType_runMultipleInstances", 'Run' -%>

                <%= scope[:form].text_field com.thoughtworks.go.config.JobConfig::RUN_INSTANCE_COUNT, :class => "inline in_between_text small_text_field" %>
                <%= label_tag "jobRunType_runMultipleInstances", 'instances' -%>
                <span class="contextual_help has_go_tip_right" title=" Specified number of instances of job will be created during schedule time."></span>
            </div>
            </div>
        </div>
    </div>
    <%= render :partial => 'shared/form_required_message.html', :locals => {:scope => {}} unless @is_config_repo_pipeline %>
    <%= render :partial => 'shared/convert_tool_tips.html', :locals => {:scope => {}} %>

<script type="text/javascript">

    Util.on_load(function() {
        function hookupResourcesAutoComplete() {
            jQuery(".resources_auto_complete").autocomplete(<%== @autocomplete_resources %>, {
                multiple: true,
                minChars: 0,
                matchContains: true,
                selectFirst: false,
                multipleSeparator: ", ",
                width: 248});

            jQuery(".elastic_profile_id").autocomplete(<%== @elastic_profile_ids %>, {
                multiple: false,
                minChars: 0,
                matchContains: true,
                selectFirst: false,
                width: 248});
        };

        hookupResourcesAutoComplete();

    });
</script>
